<?php
namespace App\Http\Controllers\portal;

use App\Http\Controllers\Controller;
use App\Http\Logic\PortalLogic;
use App\Http\Requests\Article\{
    InfoRequest,
    ListRequest,
    MiniListRequest
};
class ArticleController extends Controller
{
    public function list(ListRequest $request)
    {
        $params = $request->all();

        $page_no = $params['page_no'] ?? 1;

        $page_size = $params['page_size'] ?? 20;

        switch ($params['type']) {
            case 'open':
                $data = PortalLogic::getDisclosureList($params, $page_no, $page_size);
            break;
            case 'policy':
                $data = PortalLogic::getPolicyList($page_no, $page_size);
            break;
            case 'honor':
                $data = PortalLogic::getHonorList();
            break;
            default:
                $data = PortalLogic::getArticleList($params, $page_no, $page_size);
            break;
        }

        return $this->success($data);
    }

    public function info(InfoRequest $request)
    {
        $id = $request->input('id');

        $data = PortalLogic::getArticleInfo($id);

        return $this->success($data);
    }

    public function miniList(MiniListRequest $request)
    {
        $params = $request->all();

        $page_no = $params['page_no'] ?? 1;

        $page_size = $params['page_size'] ?? 20;

        $params['show_mini'] = 1;

        $data = PortalLogic::getArticleList($params, $page_no, $page_size);

        return $this->success($data);
    }
}
